<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<#assign base=request.contextPath  />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title></title>
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <link rel="stylesheet" href="${base}/frame/static/css/style.css">
    <link rel="icon" href="${base}/frame/static/image/code.png">
    <link rel="stylesheet" href="${base}/css/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.excheck.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.exedit.js"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery.ztree.exhide.js"></script>
</head>
<body class="body">

<div class="layui-row layui-col-space10">
    <div class="layui-col-xs12 layui-col-sm3 layui-col-md3">
        <ul id="tree" class="ztree" style="width:600px;color:#666666; background-color:white;"></ul>
    </div>
    <div class="layui-col-xs12 layui-col-sm9 layui-col-md9">
        <div class="ziyemianbiju">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
                <div class="my-btn-box">
            <span id="layerDemo">
                <span class="layui-form-label">企业成员</span>
                <div class="layui-input-inline">
                    <input type="text" id="peopleName" autocomplete="off" placeholder="名称" class="layui-input" style="height: 31px;">
                </div>

                	<button class="layui-btn  layui-btn-sm layui-btn-normal" onclick="serch()">查询</button>
	                <button data-method="offset" data-type="auto" class="layui-btn layui-btn-sm layui-btn-primary">添加员工</button>
	                <button  onclick="addPt()" data-type="auto" class="layui-btn layui-btn-sm layui-btn-danger ">添加所属企业</button>
                    <button  onclick="car()" data-type="auto" class="layui-btn layui-btn-sm layui-btn-danger ">企业分配车辆</button>
            </span>
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="del('{{d.id}}')">删除该人员</a>
                    </script>
                </div>
            </div>

        </div>
    </div>
    <script type="text/javascript" src="../frame/layui/layui.js"></script>
    <script type="text/javascript" src="../js/index.js"></script>
    <script type="text/javascript">

        // layui方法
        layui.use(['form', 'tree', 'table', 'vip_table', 'layer'], function () {

            // 操作对象
            var form = layui.form;
            var table = layui.table
                    , vipTable = layui.vip_table
                    , layer = layui.layer
                    , $ = layui.jquery;

            table.render({
                even: true,//开启隔行背景
                size: 'sm',//小尺寸的表格
                elem: '#test',
                toolbar: '#toolbarDemo',
                url: '${base}/comPeople/PeopleList',
                title: '用户数据表',
                defaultToolbar: ['filter', 'print', 'exports'],
                cols: [[
                   // {field: 'id', title: 'id',templet:function(val){
                   //     return val.LAY_INDEX
                   //  }, align: 'center'},
                    {field: 'name', title: '姓名', align: 'center'}
                    , {field: 'phone', title: '手机号', align: 'center'}
                    , {field: 'ptName', title: '所属企业名称', align: 'center'}
                    , {field: 'createTime', title: '添加时间',templet:function(val){
                            return DateFormat(val.createTime);
                        }, align: 'center'}
                    , {field: 'right', title: '操作', toolbar: '#barDemo', align: 'center'}
                ]]
                , id: 'testReload'
                ,height:480
                ,page: {
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip']
                    ,theme: '#9AC747'
                    ,limit: 10
                }, done: function (res, curr, count) {
                    this.where = {};
                }
            });
            //触发事件
            var active = {
                offset: function (othis) {


                    var checkedId = getCheckedID("tree");
                    if (checkedId === "false") {
                        layer.alert("请先选择要添加员工的企业。")
                        return;
                    }
                    var type = othis.data('type')
                            , text = othis.text();
                    layer.open({
                        type: 2
                        , title: '添加成员'
                        , offset: type
                        , area: ['360px', '270px']
                        , shadeClose: true
                        , id: 'layerDemo' + type //防止重复弹出
                        , content: '${base}/comPeople/people_Add?checkedId=' + checkedId

                    });
                }
            };

            $('#layerDemo .layui-btn').on('click', function () {
                var othis = $(this), method = othis.data('method');
                active[method] ? active[method].call(this, othis) : '';
            });
        });


        var zTreeObj,
                setting = {

                    view: {
                        selectedMulti: false,
                        showLine: true,
                        dblClickExpand: false
                    },

                    callback: {
                        //回调函数 默认展开节点
                        onAsyncSuccess: function () {
                            var treeObj = $.fn.zTree.getZTreeObj("tree");
                            treeObj.expandAll(true);

                            //过滤 顶级父节点  如果没有顶级父节点的子集  也就是说 是附属企业  那么就隐藏掉顶级节点
                            function filter(node) {
                                return (node.pId == 1);
                            }
                            var nodes = treeObj.getNodesByFilter(filter,true); // 查找节点集合
                            if(nodes==null){
                                var hidNode = treeObj.getNodes();
                                treeObj.hideNode(hidNode[0]);
                            }
                        },
                        onDblClick: zTreeOnDblClick
                    },
                    async: {
                        enable: true,
                        url: "${base}/comPeople/findPtZtree"
                    },
                    data: {
                        simpleData: {
                            enable: true,
                            idKey: "id",
                            pIdKey: "pId",
                            rootPid: 0
                        }
                    },
                    check: {
                        enable: true,
                        chkStyle: "radio",
                        radioType: "all",
                        chkboxType: {"Y": "s", "N": "p"}
                    }

                };
        //初始化树
        zTreeObj = $.fn.zTree.init($("#tree"), setting);


        function zTreeOnDblClick(event, treeId, treeNode) {
            var checkedId = treeNode.id;
            var table = layui.table;
            //表刷新方法
            table.reload('testReload', {
                url: '${base}/comPeople/PeopleList'
                , where: {ptId: checkedId} //设定异步数据接口的额外参数
                //,height: 300
            });
        }
        //搜索
        function serch() {
            var table = layui.table;
            //表刷新方法
            table.reload('testReload', {
                url: '${base}/comPeople/PeopleList'
                , where: {peopleName: $("#peopleName").val()} //设定异步数据接口的额外参数
                //,height: 300
            });
        }
        //添加企业
        function addPt(){

            var checkedId = getCheckedID("tree");
            if (checkedId === "false") {
                layer.alert("请先选择要添加的父级企业。")
                return;
            }
            if(checkedId=='1'){
                layer.alert("企业选择有误，请重新选择")
                return;
            }
            layer.open({
                type: 2
                , title: '添加企业'
                , area: ['390px', '410px']
                , content: '${base}/comPeople/addPt.html?checkedId=' + checkedId

            });
        }
        //分配车辆
        function car() {
            var checkedId = getCheckedID("tree");
            if (checkedId === "false") {
                layer.alert("请先选择要分车企业。")
                return;
            }
            layer.open({
                type: 2
                , title: '分配车辆'
                , area: ['390px', '410px']
                , content: '${base}/comCarCharge/allotcar.html?id=' + checkedId

            });
        }

        function del(id) {
            $.ajax({
                type: "POST",
                url: "${base}/comPeople/delPeople",
                data: {id:id },
                success: function (data) {
                    layer.msg(data);
                    var table = layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/comPeople/PeopleList'
                        , where: {} //设定异步数据接口的额外参数
                        //,height: 300
                    });
                }
            });
        }


            <#--$.ajax({-->
                <#--type: "POST",-->
                <#--url: "${base}/comPeople/delPeople",-->
                <#--data: {id:id },-->
                <#--success: function (data) {-->
                    <#--layer.msg(data);-->
                    <#--var table = layui.table;-->
                    <#--//表刷新方法-->
                    <#--table.reload('testReload', {-->
                        <#--url: '${base}/comPeople/PeopleList'-->
                        <#--, where: {} //设定异步数据接口的额外参数-->
                        <#--//,height: 300-->
                    <#--});-->
                <#--}-->
            <#--});-->


    </script>
</body>
</html>